package com.example.myfirstapplication.utils

import android.content.IntentFilter
import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
import com.example.myfirstapplication.receiver.OffLineRecevier

open class BaseActivity : AppCompatActivity() {

    lateinit var offLineRecevier: OffLineRecevier

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ActivityCollector.add(this)
    }

    override fun onResume() {
        super.onResume()
        val intentFilterOffLine = IntentFilter()
        intentFilterOffLine.addAction("com.example.myfirstapplication.OFFLINE")
        offLineRecevier = OffLineRecevier()
        registerReceiver(offLineRecevier, intentFilterOffLine)
    }

    override fun onPause() {
        super.onPause()
        unregisterReceiver(offLineRecevier)
    }

    override fun onDestroy() {
        super.onDestroy()
        ActivityCollector.remove(this)
    }
}